package chord.finder;

import com.juitar.base.Fingering;

public class HtmlHelper {
    
    public static String toHtmlTable(Fingering f) {
        int first = f.getFirstFret();
        StringBuffer buffer = new StringBuffer();
        buffer.append("<table class='fingering' cellpadding='0' cellspacing='0'>");
        buffer.append("<tr><td align='center'>" + f.chordName() + "</td></tr>");
        for (int i = 0; i < f.strings(); i++) {
            int fr = f.getFret(i);
            String img;
            if (fr < 0) {
                img = "<img src='x.bmp' alt='string'>";
            } else if (fr == 0) {
                img = "<img src='0.bmp' alt='string'>";
            } else if (first == 2 && f.length() <= 3) {
                img = "<img src='" + fr + ".bmp' alt='string'>";
            } else if (first == 4 && f.length() <= 3) {
                img = "<img src='" + (fr - 2) + ".bmp' alt='string'>";
            } else if (first == 6 && f.length() <= 3) {
                img = "<img src='" + (fr - 4) + ".bmp' alt='string'>";
            } else {
                img = "<img src='" + (fr - first + 1) + ".bmp' alt='string'>";
            }

            buffer.append("<tr>");
            buffer.append("<td>" + img + "</td>");
            buffer.append("</tr>");
        }
        buffer.append("<tr><td>" + f.getFirstFret() + "</td></tr>");
        buffer.append("</table>");
        return buffer.toString();
    }
}
